package Search;

import java.util.ArrayList;

import Main.Node;

public class IDS extends GSearch {

	static ArrayList<Node> Q = new ArrayList<Node>();

	public static void search(Node InitialBoard) {
		Q.add(InitialBoard);

		for (int i = 3; true; i += 3) {
			Q = new ArrayList<Node>();
			GSearch.Mem = new ArrayList<String>();
			Q.add(InitialBoard);
			while (!Q.isEmpty() && !Solved(Q.get(0))) {
				if (Q.get(0).getLevel() < i) {
					ArrayList<Node> x = expand(Q.remove(0));
					while (!x.isEmpty()) {
						if (GSearch.checkDone(x.get(0).getBoard().getB())) {
							Q.add(0, x.get(0));
						}
						x.remove(0);
					}
				} else {
					Q.remove(0);
				}
			}
			if (!Q.isEmpty() && Solved(Q.get(0))) {
				displayPath(formPath(Q.get(0)));
				System.out.println("SOLUTION!!!");
				break;
			}
		}

	}

}
